package com.tianji.learning.service.impl;

import com.tianji.common.utils.BeanUtils;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.ReplyDTO;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.mapper.InteractionReplyMapper;
import com.tianji.learning.service.IInteractionReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 互动问题的回答或评论 服务实现类
 * </p>
 *
 * @author 丁真
 * @since 2025-07-01
 */
@Service
public class InteractionReplyServiceImpl extends ServiceImpl<InteractionReplyMapper, InteractionReply> implements IInteractionReplyService {

    /**
     * 保存互动回答或评论
     *
     * @param replyDTO
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveReply(ReplyDTO replyDTO) {
        // 1.数据拷贝,保存
        InteractionReply reply = BeanUtils.toBean(replyDTO, InteractionReply.class);
        reply.setUserId(UserContext.getUser());
        reply.setHidden(false);
        save(reply);


        // 2.判断是否是回答
        if (reply.getAnswerId() != null){
            // 2.1 不是回答，累加回答下评论次数


        }

        // 2.1 是回答,修改问题表最近一次回答的id

        // 3.判断是否是学生提交

        // 3.1累加问题表回答次数




    }
}
